#include "SeriesPreview.h"

namespace LightChart
{
    SeriesPreview::SeriesPreview(QWidget* parent)
    : QDialog(parent)
    {
	Ui_SeriesPreview::setupUi(this);
	connect(closeButton, SIGNAL(clicked()), this, SLOT(onClose()));
    }
    void SeriesPreview::onClose()
    {
	hide();
	table->clear();
	table->setRowCount(0);
    }

    void SeriesPreview::displaySeries(Series* series)
    {
	show();
    switch (series->get_type()) {
    case DOUBLE_PRECISION: {
        std::vector<double>& s = series->get_double_vector();
        table->setRowCount(s.size());
        for(unsigned i = 0; i < s.size(); ++i)
        {
            table->setItem(0,i,new QTableWidgetItem(QString::number(s[i])));
        }
    }
    break;
    case INTEGER: {
        std::vector<int>& s = series->get_int_vector();
        table->setRowCount(s.size());
        for(unsigned i = 0; i < s.size(); ++i)
        {
            table->setItem(0,i,new QTableWidgetItem(QString::number(s[i])));
        }
    }
    break;
    case S_TEXT: {
        std::vector<std::string>& s = series->get_string_vector();
        table->setRowCount(s.size());
        for(unsigned i = 0; i < s.size(); ++i)
        {
            table->setItem(0,i,new QTableWidgetItem(QString(s[i].c_str())));
        }
    }
    break;
    case UNKNOWN:
        break;
    }
    }
}
